package com.wish.housing.controller;


import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.A;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wish.common.core.usconfig.common.MsgResult;
import com.wish.housing.entity.HouseInfo;
import com.wish.housing.entity.RoomInfo;
import com.wish.housing.entity.TbHouseInfo;
import com.wish.housing.entity.TbHouseStyle;
import com.wish.housing.entity.vo.rk.RackVo;
import com.wish.housing.service.IHouseInfoService;
import com.wish.housing.service.IRoomInfoService;
import com.wish.housing.service.ITbHouseStyleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 曹佳林 王泓翔-房源表 	！房态-杨子强 前端控制器
 * </p>
 *
 * @author benjamin
 * @since 2022-03-28
 */
@RestController
@RequestMapping("/house-info")
public class HouseInfoController {

    @Autowired
    IHouseInfoService iHouseInfoService;

    @Autowired
    IRoomInfoService iRoomInfoService;

    @Autowired
    ITbHouseStyleService iTbHouseStyleService;

    @GetMapping("/roomRackList")
    public MsgResult roomRackList(RackVo qv) {
        PageHelper.startPage(qv.getPageNum(), qv.getPageSize());
        List<RackVo> list = iHouseInfoService.roomRackList(qv);
        int size = list.size();
        for (int i = 0; i < size; i++) {
            RackVo rackVo = list.get(i);
            qv.setId(rackVo.getId());
            List<RoomInfo> roomList = iHouseInfoService.getRoomList(qv);
            rackVo.setRoomInfoList(roomList);
        }
        PageInfo<RackVo> pg = new PageInfo<>(list);
        return MsgResult.succeed(pg);
    }

    @PutMapping("/updateHouse")
    public MsgResult updateHouse(@RequestBody HouseInfo houseInfo) {
        iHouseInfoService.updateById(houseInfo);
        return MsgResult.succeed();
    }

}
